home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / APXMDIDV.PAK / APMDMDIC.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  224 lines

  1. //----------------------------------------------------------------------------
  2. //  Project ApxMdiDv
  3. //  Borland International
  4. //  Copyright ⌐ 1996. All Rights Reserved.
  5. //
  6. //  SUBSYSTEM:    ApxMdiDv Application
  7. //  FILE:         apmdmdic.cpp
  8. //  AUTHOR:       
  9. //
  10. //  OVERVIEW
  11. //  ~~~~~~~~
  12. //  Source file for implementation of TApxMdiDvMDIClient (TMDIClient).
  13. //
  14. //----------------------------------------------------------------------------
  15.  
  16. #include <owl/pch.h>
  17.  
  18. #include <owl/docmanag.h>
  19. #include <owl/listbox.h>
  20. #include <stdio.h>
  21.  
  22. #include "apxmddva.h"
  23. #include "apmdmdi1.h"
  24. #include "apmdmdic.h"
  25. #include "apxprint.h"
  26. #include "apxprev.h"
  27.  
  28.  
  29. //{{TApxMdiDvMDIClient Implementation}}
  30.  
  31.  
  32. //
  33. // Build a response table for all messages/commands handled
  34. // by TApxMdiDvMDIClient derived from TMDIClient.
  35. //
  36. DEFINE_RESPONSE_TABLE1(TApxMdiDvMDIClient, TMDIClient)
  37. //{{TApxMdiDvMDIClientRSP_TBL_BEGIN}}
  38.   EV_COMMAND(CM_FILEPRINT, CmFilePrint),
  39.   EV_COMMAND(CM_FILEPRINTERSETUP, CmFilePrintSetup),
  40.   EV_COMMAND(CM_FILEPRINTPREVIEW, CmFilePrintPreview),
  41.   EV_COMMAND_ENABLE(CM_FILEPRINT, CmPrintEnable),
  42.   EV_COMMAND_ENABLE(CM_FILEPRINTERSETUP, CmPrintEnable),
  43.   EV_COMMAND_ENABLE(CM_FILEPRINTPREVIEW, CmPrintEnable),
  44.   EV_WM_DROPFILES,
  45. //{{TApxMdiDvMDIClientRSP_TBL_END}}
  46. END_RESPONSE_TABLE;
  47.  
  48.  
  49. //--------------------------------------------------------
  50. // TApxMdiDvMDIClient
  51. // ~~~~~~~~~~~
  52. // Construction/Destruction handling.
  53. //
  54. TApxMdiDvMDIClient::TApxMdiDvMDIClient(TModule* module)
  55. :
  56.   TMDIClient(module)
  57. {
  58.   ChildCount = 0;
  59.  
  60.   // INSERT>> Your constructor code here.
  61.  
  62. }
  63.  
  64.  
  65. TApxMdiDvMDIClient::~TApxMdiDvMDIClient()
  66. {
  67.   Destroy();
  68.  
  69.   // INSERT>> Your destructor code here.
  70.  
  71. }
  72.  
  73.  
  74. //--------------------------------------------------------
  75. // TApxMdiDvMDIClient
  76. // ~~~~~~~~~~~
  77. // MDIClient site initialization.
  78. //
  79. void TApxMdiDvMDIClient::SetupWindow()
  80. {
  81.   // Default SetUpWindow processing.
  82.   //
  83.   TMDIClient::SetupWindow();
  84.  
  85.   // Accept files via drag/drop in the client window.
  86.   //
  87.   DragAcceptFiles(true);
  88. }
  89.  
  90.  
  91. //--------------------------------------------------------
  92. // TApxMdiDvMDIClient
  93. // ~~~~~~~~~~
  94. // Menu File Print command
  95. //
  96. void TApxMdiDvMDIClient::CmFilePrint()
  97. {
  98.   // Create Printer object if not already created.
  99.   //
  100.   TApxMdiDvApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxMdiDvApp);
  101.   if (theApp) {
  102.     if (!theApp->Printer)
  103.       theApp->Printer = new TPrinter(theApp);
  104.  
  105.     TAPointer<char> docName = new char[_MAX_PATH];
  106.  
  107.     TDocument* currentDoc = theApp->GetDocManager()->GetCurrentDoc();
  108.     if (currentDoc->GetTitle())
  109.       strcpy(docName, currentDoc->GetTitle());
  110.     else
  111.       strcpy(docName, "Document");
  112.  
  113.     // Create Printout window and set characteristics.
  114.     //
  115.     TApxPrintout printout(theApp->Printer, docName, GetActiveMDIChild()->GetClientWindow(), true);
  116.  
  117.     theApp->Printing++;
  118.  
  119.     // Bring up the Print dialog and print the document.
  120.     //
  121.     theApp->Printer->Print(GetWindowPtr(GetActiveWindow()), printout, true);
  122.  
  123.     theApp->Printing--;
  124.   }
  125. }
  126.  
  127.  
  128. //--------------------------------------------------------
  129. // TApxMdiDvMDIClient
  130. // ~~~~~~~~~~
  131. // Menu File Print Setup command
  132. //
  133. void TApxMdiDvMDIClient::CmFilePrintSetup()
  134. {
  135.   TApxMdiDvApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxMdiDvApp);
  136.   if (theApp) {
  137.     if (!theApp->Printer)
  138.       theApp->Printer = new TPrinter(theApp);
  139.  
  140.     // Bring up the Print Setup dialog.
  141.     //
  142.     theApp->Printer->Setup(this);
  143.   }
  144. }
  145.  
  146.  
  147. //--------------------------------------------------------
  148. // TApxMdiDvMDIClient
  149. // ~~~~~~~~~~
  150. // Menu File Print Preview command
  151. //
  152. void TApxMdiDvMDIClient::CmFilePrintPreview()
  153. {
  154.   TApxMdiDvApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxMdiDvApp);
  155.   if (theApp) {
  156.     if (!theApp->Printer)
  157.       theApp->Printer = new TPrinter(GetApplication());
  158.  
  159.     theApp->Printing++;
  160.  
  161.     TApxPreviewWin* prevW = new TApxPreviewWin(Parent, theApp->Printer, GetActiveMDIChild()->GetClientWindow(), "Print Preview", new TLayoutWindow(0));
  162.     prevW->Create();
  163.  
  164.     // Here we resize the preview window to take the size of the MainWindow, then
  165.     // hide the MainWindow.
  166.     //
  167.     TFrameWindow * mainWindow =  GetApplication()->GetMainWindow();
  168.     TRect r = mainWindow->GetWindowRect();
  169.     prevW->MoveWindow(r);
  170.     prevW->ShowWindow(SW_SHOWNORMAL);
  171.     mainWindow->ShowWindow(SW_HIDE);
  172.  
  173.     GetApplication()->BeginModal(GetApplication()->GetMainWindow());
  174.  
  175.     // After the user closes the preview Window, we take its size and use it
  176.     // to size the MainWindow, then show the MainWindow again.
  177.     //
  178.     r = prevW->GetWindowRect();
  179.     mainWindow->MoveWindow(r);
  180.     mainWindow->ShowWindow(SW_SHOWNORMAL);
  181.  
  182.     // We must destroy the preview window explicitly.  Otherwise, the window will
  183.     // not be destroyed until it's parent the MainWindow is destroyed.
  184.     //
  185.     prevW->Destroy();
  186.     delete prevW;
  187.  
  188.     theApp->Printing--;
  189.   }
  190. }
  191.  
  192.  
  193. //--------------------------------------------------------
  194. // TApxMdiDvMDIClient
  195. // ~~~~~~~~~~
  196. // Menu enabler used by Print, Print Setup and Print Preview.
  197. //
  198. void TApxMdiDvMDIClient::CmPrintEnable(TCommandEnabler& tce)
  199. {
  200.   if (GetActiveMDIChild()) {
  201.     TApxMdiDvApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxMdiDvApp);
  202.     if (theApp) {
  203.       // If we have a Printer already created just test if all is okay.
  204.       // Otherwise create a Printer object and make sure the printer really
  205.       // exists and then delete the Printer object.
  206.       //
  207.       if (!theApp->Printer) {
  208.         theApp->Printer = new TPrinter(theApp);
  209.         tce.Enable(!theApp->Printer->GetSetup().Error);
  210.       }
  211.       else
  212.         tce.Enable(!theApp->Printer->GetSetup().Error);
  213.     }
  214.   }
  215.   else
  216.     tce.Enable(false);
  217. }
  218.  
  219.  
  220. void TApxMdiDvMDIClient::EvDropFiles(TDropInfo)
  221. {
  222.   Parent->ForwardMessage();
  223. }
  224.